// pages/playlist/playlist.js
const MAX_LIMIT = 15
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperImgUrls: [
      {
        url: 'http://p1.music.126.net/6ijUOzxIJMCAb-WiqALK-g==/109951164614624218.jpg',
      },
      {
        url: 'http://p1.music.126.net/Cr953N4vBoBKVfGBylpTaw==/109951164613505036.jpg',
      },
      {
        url: 'http://p1.music.126.net/4-fLaGynVPdlP03c-GSMCA==/109951164613488421.jpg',
      }   
    ],
  playlist:[
    { "_id": "08560c9e5d042a5d0174f1ea32c4c288", "type": 0.0, "copywriter": "热门推荐", "highQuality": false, "createTime": { "$date": "2019-06-14T23:14:37.097Z" }, "id": 2.201879658e+09, "alg": "cityLevel_unknow", "playCount": 1.06749088e+08, "name": "你的青春里有没有属于你的一首歌？", "picUrl": "https://p2.music.126.net/wpahk9cQCDtdzJPE52EzJQ==/109951163271025942.jpg", "canDislike": true, "trackCount": 169.0 },
    { "_id": "08560c9e5d042a5c0174f1de21c7e79e", "id": 2.828842343e+09, "type": 0.0, "name": "粤语情诗：与你听风声，观赏过夜星", "picUrl": "https://p2.music.126.net/K9IcG8cU6v4_SwuQ_x2xMA==/109951164124604652.jpg", "highQuality": false, "alg": "cityLevel_unknow", "playCount": 1.785097e+06, "trackCount": 52.0, "copywriter": "热门推荐", "canDislike": true, "createTime": { "$date": "2019-06-14T23:14:36.982Z" }},    { "_id": "08560c9e5d042a5c0174f1da7aa357aa", "highQuality": false, "copywriter": "热门推荐", "canDislike": true, "playCount": 622822.6, "id": 2.740107647e+09, "name": "「时空潜行」囿于昼夜的空想主义者", "type": 0.0, "alg": "cityLevel_unknow", "createTime": { "$date": "2019-06-14T23:14:36.955Z" }, "picUrl": "https://p2.music.126.net/Q0eS0avwGK04LufWM7qJug==/109951164116217181.jpg", "trackCount": 20.0 },

    
  ]
  },
  toMore() {
    wx.navigateTo({
      url: '/pages/morePlaylist/morePlaylist',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
   this.getPlaylist()
  },
  getPlaylist() {
    wx.cloud.callFunction({
      name: 'music',
      data: {
        start: this.data.playlist.length,
        count: MAX_LIMIT,
        $url: 'playlist'
      }
    }).then((res) => {
      this.setData({
        playlist: this.data.playlist.concat(res.result.data)
      })
      wx.stopPullDownRefresh()
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({
      playlist: []
    })
    this.getPlaylist()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getPlaylist()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})